package m.framework.test.db;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import m.framework.dao.mapping.SqlType;
import m.framework.dao.mapping.SqlUtil;
import m.framework.dao.model.BaseModel;
import m.framework.dao.selector.Query;
import m.framework.exception.SystemException;
import m.framework.service.BaseService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author ming
 * @date 2014年2月20日上午11:30:43
 */
public class BaseServiceMock extends BaseService {
	private static Logger log = LoggerFactory.getLogger(BaseServiceMock.class);
	//该类总共执行的sql;
	private List<String> sqls=new ArrayList();
	//方法调用的返回值,调用前push,调用后pop
	private LinkedList result=new LinkedList();
	
	public void addResult(Object obj){
		result.push(obj);
	}
	
	public List query(Query query) {
		String sql=SqlUtil.mySql().createSql(query, SqlType.SELECT);
		sql=SqlUtil.format(sql, query.paras());
		sqls.add(sql);
		log.debug("假装执行sql:\n"+sql);
		return (List) pop();
	}
	
	private Object pop(){
		if(result.size()==0){
			return null;
		}
		return result.pop();
	}
	
	public List<String> getSqls(){
		return sqls;
	}
	
	
	
	public int insert(BaseModel baseModel){
		throw new SystemException("未实现");
	}
	
	public void updateFull(BaseModel baseModel){
		throw new SystemException("未实现");
	}
	
	
	

	public void insertList(List result) {
		throw new SystemException("未实现");
	}

	public Integer deleteByQuery(Query q) {
		throw new SystemException("未实现");
	}

	public Integer updateByQuery(BaseModel m, Query q) {
		throw new SystemException("未实现");
	}
}




